package com.gxw.rxjavatest.Presenter;

import android.util.Log;

import com.gxw.rxjavatest.activity.View.UpImageView;
import com.gxw.rxjavatest.model.ImageModel;
import com.gxw.rxjavatest.model.bean.ImageResponse;
import com.gxw.rxjavatest.model.bean.UpLogin;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by GXW on 2016/4/12 0012.
 * email:603004002@qq.com
 */
public class UpImagePresenter {

    private String TAG = UpImagePresenter.class.getName().toString();

    private UpImageView upImageView;
    private ImageModel imageModel;

    public UpImagePresenter(UpImageView upImageView) {
        this.upImageView = upImageView;
        imageModel = new ImageModel();
    }

    public void upImage(UpLogin upLogin, String imgStr, final int i) {

//        Log.i(TAG, upLogin.getLoginID() + " " + upLogin.getPassword() + " " + upLogin.getDeviceType());
//        Log.i(TAG, imgStr);

        String s = imageModel.upImage(upLogin, imgStr).toString();
        Log.i(TAG, s);

        imageModel.upImage(upLogin, imgStr).enqueue(new Callback<ImageResponse>() {
            @Override
            public void onResponse(Call<ImageResponse> call, Response<ImageResponse> response) {

                ImageResponse body = response.body();
                String data = body.getData();

                Log.i(TAG, i + " - ninin:" + data);

                switch (i) {
                    case 1:

                        upImageView.upImageStateF(data);

                        break;
                    case 2:

                        upImageView.upImageStateS(data);

                        break;
                    case 3:

                        upImageView.upImageStateT(data);

                        break;
                    case 4:

                        upImageView.upImageStateFor(data);

                        break;
                }

            }

            @Override
            public void onFailure(Call<ImageResponse> call, Throwable t) {
                Log.i(TAG, "++++++++++++++++" + t.getMessage());
            }
        });

    }

}
